/*
Copyright (c) 2010 Vadim Seregin
Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
*/


#ifndef CARDWORDLIST_H
#define CARDWORDLIST_H

#include "baselist.h"
#include "wx/wxsqlite3.h"
#include "../../res/cardworddialog.h" // Base class: CardWordDialog
#include "dictlist.h"
#include "wordlist.h"
#include "dblink.h"

class CardWordList : public CardWordDialog, public BaseList
{

public:
	CardWordList( DbLink* pcDbLink, wxString& cardTableName, wxString& soundFileDir );
	~CardWordList();

	// load words
	void Load();

protected:
	// get score
	wxString GetScore(){ return m_textCtrlScore->GetLineText(0); }
	
	// set score
	void SetScore( wxString& str ){ m_textCtrlScore->SetValue( str ); }
	
	// fill list with dicts and return the number of dicts
	long FillList( bool bClear = false );
	
	// clear info
	void ClearInfo();

	// clear word info
	void SetInfo();
	
	// update item in the list
	void UpdateItem();

	// ======================== events ================================
	// create or update dict
	virtual void OnOkClick( wxCommandEvent& event );
	
	// if list item is selected
	virtual void OnWordSelected( wxListEvent& event );
	
	// if list item is deselected
	virtual void OnWordDeselected( wxListEvent& event );
	
	// add word
	virtual void OnAddClick( wxCommandEvent& event );
	
	// delete word
	virtual void OnDeleteClick( wxCommandEvent& event );
	
	// play file
	virtual void OnPlayClick( wxCommandEvent& event );
	
	// left double click
	virtual void OnLeftDClick( wxMouseEvent& event ) { OnPlayClick( (wxCommandEvent&) event ); }
	
	// key down
	virtual void OnKeyDown( wxKeyEvent& event );

	// enter window
	virtual void OnEnterWindow( wxMouseEvent& event );

protected:
	enum eWordList
	{
		eWordList_Id = 0,
		eWordList_TableName,
		eWordList_Word,
		eWordList_Tran,
		eWordList_Score,
		eWordList_Cols
	};
	
	wxSQLite3Database *m_pDictDb;   // pointer to dict database
	wxSQLite3Database *m_pCardDb;   // pointer to card database
	
	wxString m_sCardTableName;      // card db table name
	wxString m_sDictTableName;      // dict db table name
	wxString m_sWordId;             // word id in the dict db table
	wxString m_sScore;              // score of the word
	long     m_lWordNum;            // number of words

	DbLink* m_pcDbLink;             // link to db

};

#endif // CARDWORDLIST_H
